const TOKEN_KEY = "login_device";
const USER_KEY = "zg_user";
import Cookie from "js-cookie";

import getStore from "@/redux/store";
import { initialUserInfoAction } from "@/redux/actions";

const checkWindow = () => {
  if (typeof window === "undefined") {
    return false;
  } else {
    return true;
  }
};

export const getCookie = () => {
  if (!checkWindow()) return;
  return Cookie.get(TOKEN_KEY);
};
export const removeCookie = () => {
  if (!checkWindow()) return;
  return Cookie.remove(TOKEN_KEY);
};

export const clearAuth = function () {
  if (!checkWindow()) return;
  removeCookie();
  getStore({}).dispatch(initialUserInfoAction());
};
